"""
数据库模型定义
"""
from app import db


class Employee(db.Model):
    """员工信息模型"""
    __tablename__ = 'employees'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), nullable=False, comment='姓名')
    department = db.Column(db.String(100), comment='部门名称')
    position = db.Column(db.String(100), comment='岗位名称')
    title = db.Column(db.String(100), comment='职务')
    level = db.Column(db.String(20), comment='职级')
    tags = db.Column(db.String(200), comment='关键标签')

    def to_dict(self):
        """转换为字典格式"""
        return {
            'id': self.id,
            'name': self.name,
            'department': self.department,
            'position': self.position,
            'title': self.title,
            'level': self.level,
            'tags': self.tags
        }


class Organization(db.Model):
    """组织信息模型"""
    __tablename__ = 'organizations'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), nullable=False, comment='组织名称')
    total_employees = db.Column(db.Integer, comment='总人数')
    formal_employees = db.Column(db.Integer, comment='正式工总人数')
    gender_ratio = db.Column(db.String(20), comment='男女比例')
    avg_age = db.Column(db.Float, comment='平均年龄')
    avg_tenure = db.Column(db.String(50), comment='平均司龄')
    management_positions = db.Column(db.Integer, comment='管理岗人数')
    reporting_depth = db.Column(db.Float, comment='平均汇报深度')
    management_span = db.Column(db.Float, comment='平均管理幅度')
    probation_count = db.Column(db.Integer, comment='试用期人数')
    party_member_ratio = db.Column(db.Float, comment='党员比例')
    campus_recruit_ratio = db.Column(db.Float, comment='校招生比例')
    new_employee_ratio = db.Column(db.Float, comment='近一年新员工比例')
    turnover_rate = db.Column(db.Float, comment='近一年离职率')
    officer_soldier_ratio = db.Column(db.String(20), comment='官兵比')

    def to_dict(self):
        """转换为字典格式"""
        return {
            'id': self.id,
            'name': self.name,
            'total_employees': self.total_employees,
            'formal_employees': self.formal_employees,
            'gender_ratio': self.gender_ratio,
            'avg_age': self.avg_age,
            'avg_tenure': self.avg_tenure,
            'management_positions': self.management_positions,
            'reporting_depth': self.reporting_depth,
            'management_span': self.management_span,
            'probation_count': self.probation_count,
            'party_member_ratio': self.party_member_ratio,
            'campus_recruit_ratio': self.campus_recruit_ratio,
            'new_employee_ratio': self.new_employee_ratio,
            'turnover_rate': self.turnover_rate,
            'officer_soldier_ratio': self.officer_soldier_ratio
        }
